/**
 * 
 */
package com.ksframework.security.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.ksframework.common.entity.BaseEntity;

/**
 * @description
 * user role entity
 * @author ssocenter
 * @date 2011-8-26
 */
@SuppressWarnings("serial")
@Entity
@Table(name="security_role")
public class Role extends BaseEntity {
	private String name;
	private String description;
	private Set<User> users = new HashSet<User>();
	private Set<Resource> resources = new HashSet<Resource>();
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	@ManyToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="roles",targetEntity=User.class)
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	@ManyToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	@JoinTable(name = "role_resource", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "resource_id"))
	public Set<Resource> getResources() {
		return resources;
	}
	public void setResources(Set<Resource> resources) {
		this.resources = resources;
	}
}
